import asyncio
from pathlib import Path
from playwright.async_api import async_playwright


async def main():
    out_path = Path(__file__).resolve().parents[1] / 'artifacts' / 'luogu-322081' / 'storage_state.json'
    out_path.parent.mkdir(parents=True, exist_ok=True)
    async with async_playwright() as pw:
        browser = await pw.chromium.launch(headless=False)
        context = await browser.new_context()
        page = await context.new_page()
        await page.goto('https://www.luogu.com.cn/record/list?user=322081&page=104')
        print('请在打开的浏览器中完成登录，然后回到此窗口按回车保存会话。')
        input()
        await context.storage_state(path=str(out_path))
        await browser.close()
    print('已保存会话到', out_path)


if __name__ == '__main__':
    asyncio.run(main())

